﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
namespace TDT_Project.classes
{
    public class cls_anh_nen
    {
        int _id_anh = 0;
        public int id_anh
        {
            get { return _id_anh; }
            set { _id_anh = value; }
        }

        string _hinh_anh = "";
        public string hinh_anh
        {
            get { return _hinh_anh; }
            set { _hinh_anh = value; }
        }

        int _is_active = 0;
        public int is_active
        {
            get { return _is_active; }
            set { _is_active = value; }
        }

        public bool Update_AnhNen(Int32 ID)
        {

            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("CapNhatHinhNen", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Parameters.Add("@ID", SqlDbType.Int).Value = ID;
            bool bReturn = false;
            try
            {
                oConnection.Open();
                oCommand.ExecuteNonQuery();
                bReturn = true;
            }
            catch
            {
                return bReturn;
            }
            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return bReturn;
        }
        public bool Toan_Insert_anh_nen()
        {
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("Toan_Insert_anh_nen", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Parameters.Add("@hinh_anh", SqlDbType.NVarChar).Value = hinh_anh;
            oCommand.Parameters.Add("@is_active", SqlDbType.NVarChar).Value = is_active;
            bool bReturn = false;
            try
            {
                oConnection.Open();
                oCommand.ExecuteNonQuery();
                bReturn = true;
            }
            catch
            {
                return bReturn;
            }
            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return bReturn;
        }

        public bool TOAN_Update_anh_nen()
        {
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_Update_anh_nen", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Parameters.Add("@id_anh", SqlDbType.Int).Value = id_anh;          
            oCommand.Parameters.Add("@is_active", SqlDbType.Int).Value = is_active;
            bool bReturn = false;
            try
            {
                oConnection.Open();
                oCommand.ExecuteNonQuery();
                bReturn = true;
            }
            catch
            {
                return bReturn;
            }
            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return bReturn;
        }

        public DataSet TOAN_get_all_anh_nen()
        {
            DataSet results = new DataSet();
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_get_all_anh_nen", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = oCommand;
            da.Fill(results);

            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return results;

        }
        public DataSet Load_AnhNen()
        {
            DataSet results = new DataSet();
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("Load_AnhNen", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = oCommand;
            da.Fill(results);

            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return results;

        }
        public DataSet TOAN_getall_anh_nen_ID(int idanh)
        {
            DataSet results = new DataSet();
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_getall_anh_nen_ID", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Parameters.Add("@id_anh", SqlDbType.Int).Value = idanh;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = oCommand;
            da.Fill(results);

            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return results;
        }


        public bool TOAN_Delete_anh_nen(int id_anh)
        {
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_Delete_anh_nen", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Parameters.Add("@id_anh", SqlDbType.Int).Value = id_anh;
            bool bReturn = false;
            try
            {
                oConnection.Open();
                oCommand.ExecuteNonQuery();
                bReturn = true;
            }
            catch
            {
                return false;
            }
            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return bReturn;
        }


    }
}